package com.itheima.TCPdemo;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class Client {//客服端，TCP协议发送数据
    public static void main(String[] args) throws IOException {

        //1创建socket对象
        //细节，创建对象同时会连接服务端，连接不上代码报错
        //Exception in thread "main" java.net.ConnectException: Connection refused: connect

        Socket socket=new Socket("127.0.0.1",10000);
        //127.0.0.1是要连接的服务端的ip，这个意思就是让本机当服务端,有主次结构

        //2.可以从连接通道中获取输出流
        OutputStream os = socket.getOutputStream();//ctrl+alt+v补全
        os.write("你好".getBytes());//字节流写出只能用字节信息



        os.close();
        socket.close();
    }
}
